package knowall.server;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.Embedded;
import javax.jdo.annotations.EmbeddedOnly;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

public class QuestionStack {

	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
	private String id;
	@Persistent
	private String userId;
	
	@PersistenceCapable
    @EmbeddedOnly
    public static class StackEntry {
        @Persistent
        private Date date;
        @Persistent
        private String questionId;
        @Persistent
        private Integer numRetries;
		
        private StackEntry() {
        	
        }
        
        public StackEntry(Date date, String questionId, Integer numRetries) {
        	this();
        	this.setDate(date);
        	this.setQuestionId(questionId);
        	this.setNumRetries(numRetries);
        }
        
        public Date getDate() {
			return date;
		}
		public void setDate(Date date) {
			this.date = date;
		}
		public String getQuestionId() {
			return questionId;
		}

		public void setQuestionId(String questionId) {
			this.questionId = questionId;
		}

		public Integer getNumRetries() {
			return numRetries;
		}
		public void setNumRetries(Integer numRetries) {
			this.numRetries = numRetries;
		}
        
    }
	
	@Persistent
    @Embedded
	private List<StackEntry> stackEntries = new ArrayList<StackEntry>();

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public List<StackEntry> getStackEntries() {
		return stackEntries;
	}

	public void setStackEntries(List<StackEntry> stackEntries) {
		this.stackEntries = stackEntries;
	}
	
	public void push(String questionId) {
		stackEntries.add(new StackEntry(new Date(), questionId, 10));
	}
	
	public StackEntry pop() {
		StackEntry se = stackEntries.get(0);
		stackEntries.remove(0);
		return se;
	}
}
